package com.wind.httpProxyServer.manager;

import com.wind.httpProxyServer.HttpProxyServer;
import com.wind.httpProxyServer.bean.ProcessConfigBean;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class HttpProxyServerManager {
    public static Map<Long,HttpProxyServer> httpProxyServerMap =new ConcurrentHashMap<>();


    public static void start(ProcessConfigBean processConfigBean){
        HttpProxyServer httpProxyServer = new HttpProxyServer(processConfigBean);

        new Thread("proxy:["+processConfigBean.getPort()+"]"){
            @Override
            public void run() {
                httpProxyServer.start();
            }
        }.start();


        httpProxyServerMap.put(processConfigBean.getId(),httpProxyServer);

    }

    public static void close(ProcessConfigBean processConfigBean){
        HttpProxyServer httpProxyServer = httpProxyServerMap.get(processConfigBean.getId());
        if(httpProxyServer!=null){
            httpProxyServer.close();
        }
    }

}
